package com.sjy.common.result;


import org.springframework.http.ResponseEntity;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel(description = "通用响应返回对象")
public class BaseResponse<T> {
    @ApiModelProperty(value = "返回码：正确200, 错误500，错误为自定义码")
    private int code;
    @ApiModelProperty(value = "返回消息")
    private String msg;
    @ApiModelProperty(value = "返回具体内容")
    @JsonInclude(Include.ALWAYS)
    private T data;
 
    public BaseResponse(int code, String message, T data) {
        this.code = code;
        this.msg = message;
        this.data = data;
    }
    
    public static ResponseEntity generateOKResponseEntity() {
        return ResponseEntity.ok().body(new BaseResponse<>(ResponseCode.CODE_SUCCESS.getCode(), "操作成功",null));
    }
    
    
    //这两个方法写在这里纯粹为了省地儿 
    public static ResponseEntity generateOKResponseEntity(Object object) {
        return ResponseEntity.ok().body(new BaseResponse<>(ResponseCode.CODE_SUCCESS.getCode(), "操作成功", object));
    }
    
    public static ResponseEntity generateOKResponseEntity(String message,Object object) {
        return ResponseEntity.ok().body(new BaseResponse<>(ResponseCode.CODE_SUCCESS.getCode(), message, object));
    }
    
    //这两个方法写在这里纯粹为了省地儿 
    public static ResponseEntity generateWarnResponseEntity(Object object) {
        return ResponseEntity.ok().body(new BaseResponse<>(ResponseCode.CODE_WARN.getCode(), "操作失败", object));
    }
    
    public static ResponseEntity generateWarnResponseEntity(String message,Object object) {
        return ResponseEntity.ok().body(new BaseResponse<>(ResponseCode.CODE_WARN.getCode(), message, object));
    }
    
    public static ResponseEntity generateBadResponseEntity() {
        return ResponseEntity.ok().body(
                new BaseResponse<>(ResponseCode.CODE_ERROR.getCode(), "操作失败", null));
    }
    
    public static ResponseEntity generateBadResponseEntity(String message, Object object) {
        return ResponseEntity.ok().body(
                new BaseResponse<>(ResponseCode.CODE_ERROR.getCode(), message, object));
    }
 
    public static ResponseEntity generateBadResponseEntity(int code, String message, Object object) {
        return ResponseEntity.ok().body(
                new BaseResponse<>(code, message, object));
    }
	public int getCode() {
		return code;
	}
	public void setCode(int code) {
		this.code = code;
	}
	
	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public T getData() {
		return data;
	}
	public void setData(T data) {
		this.data = data;
	}
 
    
}
